<template>
  <div class="user-info">
    <el-form :model="userInfo" label-width="100px">
      <el-form-item label="手机">
        <el-input v-model="userInfo.mobile" placeholder="" disabled />
      </el-form-item>
      <el-form-item label="工号">
        <el-input v-model="userInfo.workNumber" />
      </el-form-item>
      <el-form-item label="入职时间">
        <el-date-picker
          v-model="userInfo.timeOfEntry"
          type="date"
          placeholder="选择日期"
        />
      </el-form-item>
      <el-form-item label="头像">
        <UploadImage />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="hSubmit"> 确定 </el-button>
        <el-button type="info">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getEmployeeDetailAPI, updateEmployeeDetailAPI } from '@/api/employees'
import UploadImage from '@/components/UploadImage/index.vue'
export default {
  components: { UploadImage },
  props: {
    curId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      userInfo: {}
    }
  },
  created() {
    this.getEmployeeDetail()
  },
  methods: {
    // 表单提交按钮
    hSubmit() {
      this.updateEmployeeDetail()
    },
    // 保存信息
    async updateEmployeeDetail() {
      try {
        await updateEmployeeDetailAPI(this.userInfo)
        // console.log('', res)
        // this.$Massage.success('修改成功')
      } catch (err) {
        // console.log('', err)
      }
    },
    // 数据回填
    async getEmployeeDetail() {
      try {
        const res = await getEmployeeDetailAPI(this.curId)
        // console.log('', res)
        // 保存数据
        this.userInfo = res.data
      } catch (err) {
        console.log('', err)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.user-info {
  padding-right: 600px;
}
</style>
>
